import { customTable } from '@/components/ProTable/interface';
import { ProTableValue } from '@/interface/public';
import { DrawerDataProps } from '@/hooks/table/use-drawer';
import { useFormAddCampus } from './use-formAddCampus';

export function useDataCampus(detailRef: ProTableValue, drawerData: DrawerDataProps['drawerData']) {
  const { formAddCampus } = useFormAddCampus(detailRef);
  let dataCampus = reactive<customTable>({
    initParam: {
      modelId: ''
    },
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 140 },
      {
        label: '地址信息',
        prop: 'address'
      },
      {
        label: '排序',
        prop: 'showOrder'
      },

      {
        label: '排序',
        prop: 'sort'
      }
    ],
    headButtonList: [
      {
        label: 'add',
        type: 'primary',
        icon: 'Plus',
        // permissionCode: "dictionary:save",
        methods: async () => {
          if (!drawerData.row.id) {
            elMessage('请选择模板', 'warning');
            return;
          }
          formOpen(formAddCampus, '新增地址', {
            modelId: drawerData.row.id
          });
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: "system:save",
        methods: (row: any) => {
          formOpen(formAddCampus, '编辑地址', row);
        },
        attrs: {
          link: true
        }
      },
      {
        label: '删除',
        type: 'danger',
        methods: row => {
          const params = { id: row.id, modelId: row.modelId };
          useHandleData(modelRemoveAddress, params, `删除${row.address}`, detailRef.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  return { dataCampus, formAddCampus };
}
